<template>
  <view>
    <button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
	  <image class="avatar" :src="avatarUrl"></image>
	</button> 
	<input type="nickname" class="weui-input" placeholder="请输入昵称" :value="nickname"/>

	<view class="action-btn" style="margin: 200rpx;" v-if="!showForm">
		<button @click="handleWxLogin" class="login-btn cu-btn block bg-blue lg round">微信登录</button>
	</view>
  </view>
</template>

<script>
	
  import { updateUserProfile } from '@/api/system/user'
	const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

  export default {
    data() {
      return {
        params: {},
        avatarUrl: defaultAvatarUrl,
		nickname:""
      }
    },
    props: {
    },
    onLoad(event) {
     
    },
	methods:{
		onChooseAvatar(e) {
			console.log(e)
			const avatarUrl  = e.detail 
			this.avatarUrl = avatarUrl
		},
		handleWxLogin(){
			updateUserProfile({"nickname":nickname,"imageUrl":this.avatarUrl}).then(()=>{
				uni.redirectTo({
					url:"/pages/index"
				})
			})
		}
	}
  }
</script>
<style lang="scss" scoped>
	.login-btn {
	  margin-top: 40px;
	  height: 45px;
	}
</style>